home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / Peter Lewis (TCPExample) / PNL Libraries / MyGrowZones.p < prev    next >
Encoding:
Text File  |  1995-12-11  |  1.6 KB  |  89 lines  |  [TEXT/CWIE]

  1. unit MyGrowZones;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types;
  7.  
  8.     procedure StartupGrowZones;
  9.     procedure ConfigureGrowZones(size: longint);
  10.     function MemoryCritical: boolean;
  11.     function EnoughSpace (total, contig: longint): boolean;
  12.     procedure IdleGrowZone; { Called by IdleStartup, you can call it yourself }
  13.  
  14. implementation
  15.  
  16.     uses
  17.         Memory, OSUtils, 
  18.         PreserveA5, MyCallProc, MyStartup;
  19.  
  20.     var
  21.         gzh: handle;
  22.         gz_size: longINt;
  23.  
  24.     function MyGrowZone (size: longint): longint;
  25.         var
  26.             saved_A5:Ptr;
  27.     begin
  28.         size:=size; { UNUSED! }
  29.         saved_A5 := SetPreservedA5;
  30.         if gzh <> nil then begin
  31.             MyGrowZone := GetHandleSize(gzh);
  32.             DisposeHandle(gzh);
  33.             gzh := nil;
  34.         end else begin
  35.             MyGrowZone := 0;
  36.         end;
  37.         RestoreA5(saved_A5);
  38.     end;
  39.  
  40.     function MemoryCritical: boolean;
  41.     begin
  42.         MemoryCritical := gzh = nil;
  43.     end;
  44.  
  45.     function EnoughSpace (total, contig: longint): boolean;
  46.         var
  47.             t, c: longint;
  48.     begin
  49.         PurgeSpace(t, c);
  50.         EnoughSpace := not MemoryCritical & (t >= total) & (c >= contig);
  51.     end;
  52.  
  53.     procedure IdleGrowZone;
  54.     begin
  55.         if gzh = nil then begin
  56.             gzh := NewHandle(gz_size);
  57.         end;
  58.     end;
  59.  
  60.     procedure ConfigureGrowZones(size: longint);
  61.     begin
  62.         StartupGrowZones;
  63.         gz_size := size;
  64.     end;
  65.     
  66.     function InitGrowZone(var msg: integer): OSStatus;
  67.     begin
  68.         msg := msg; { Unused }
  69.         SetGrowZone(NewProc(@MyGrowZone,uppPascal44ProcInfo));
  70.         gzh := nil;
  71.         IdleGrowZone;
  72.         InitGrowZone := noErr;
  73.     end;
  74.  
  75.     procedure FinishGrowZone;
  76.     begin
  77.         if gzh <> nil then begin
  78.             DisposeHandle(gzh);
  79.             gzh := nil;
  80.         end;
  81.     end;
  82.  
  83.     procedure StartupGrowZones;
  84.     begin
  85.         StartupPreserveA5;
  86.         SetStartup(InitGrowZone, IdleGrowZone, 30, FinishGrowZone);
  87.     end;
  88.     
  89. end.